package cn.flkj.gmca.ca.sm4;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import javax.crypto.KeyGenerator;
import java.security.SecureRandom;
import java.security.Security;

/**
 * @author : 州长在手 2020/12/14 下午4:51
 */
public class SM4KeyHelper {
    static{

    if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null){

        //System.out.println("security provider BC not found");

        Security.addProvider(new BouncyCastleProvider());

    }

}

    public static byte[] generateKey() throws Exception{
        KeyGenerator kg = KeyGenerator.getInstance("SM4", BouncyCastleProvider.PROVIDER_NAME);
        kg.init(128, new SecureRandom());
        return kg.generateKey().getEncoded();
    }
}
